from CloudEngine.Render import Application
import CloudEngine.core.ArrayPlus as ArrayPlus
from CloudEngine.core.VTActor import VTActor


class NormalSystem:
    def __init__(self, parent: Application):
        self.parent = parent
        self.normalActors = ArrayPlus.ArrayPlus([])

    def callback(self, actor: VTActor, index: int):
        if actor.triggerNormalUpdate == 0:
            return
        else:
            if actor.is_show_normals():
                b = actor.get_normal_actor()
                if b is not None:
                    self.parent.renderer.AddActor(b)
            else:
                b = actor.get_normal_actor()
                if b is not None:
                    self.parent.renderer.RemoveActor(b)

    def update(self):
        ac_list = self.parent.actorList
        ac_list.for_each(self.callback)
